<template>
  <div>
    <form @submit.prevent="upd">
      <p>书名:<input type="text" v-model="bookname"></p>
      <p>价格:<input type="text" v-model="price"></p>
      <p>提交:<input type="submit"></p>
    </form>
  </div>
</template>

<script>
  import axios from 'axios'

  export default {
    name: "UPD",
    data: function () {
      return {
        cc: this.$route.params.id,
        bookname: '',
        price: 0

      }
    },
    created() {
      axios({
        url: `http://localhost:8000/myapp/updbook/${this.cc}`,
        method: 'get'
      }).then(res => {
        console.log(res.data);
        this.bookname = res.data.data.bookname
        this.price = res.data.data.price
      })
    },
    methods: {
      upd() {
        let Formdata = new FormData();
        Formdata.append('id', this.cc);
        Formdata.append('bookname', this.bookname);
        Formdata.append('price', this.price);
        axios({
          url: 'http://localhost:8000/myapp/updbook/',
          method: 'post',
          data: Formdata
        }).then(res=>{
          window.location.href = '/show'
        })
      }
    }
  }
</script>

<style scoped>

</style>

